# coding: utf-8


'''
http://wiki.it.yzs.io:8090/pages/viewpage.action?pageId=34414545
crender - check
'''
import time
from selenium import webdriver

astroTuple = ('水瓶座','双鱼座','白羊座','金牛座','双子座','巨蟹座','狮子座','处女座','天秤座','天蝎座','射手座','摩羯座')

cityTuple = ('北京', '上海', '深圳', '广州')

baikeWord = ('猴子', '比特币', '人工智能', '火龙果')

URL_List = []

def open_url_list_in_browser():
    br = webdriver.Chrome()
    print "浏览器中打开所有URL: %d个" % len(URL_List)
    for url in URL_List:
        br.get(url)
        time.sleep(1)

def append_to_url_list(url, params):
    kvs = ""
    for k,v in params.items():
        if k == 'appSecret':
            continue
        kvs += "&%s=%s" % (k,v)
    url = url + kvs
    if url not in URL_List:
        URL_List.append(url)

def today(nodash=False):
    d = time.strftime('%Y-%m-%d',time.localtime(time.time()))
    if nodash:
        return d.replace('-', '')
    return d

def weather():
    path =  '/webhook/tq?'
    params = {}
    for city in cityTuple:
        params = {
            'cityName' : city,
            'weatherDate' : today(),
            'dayCount' : '1',
        }
        append_to_url_list(URI + path, params)

def baike():
    path =  '/webhook/bk?'
    params = {}
    for word in baikeWord:
        params = {
            'word' : word,
        }
        append_to_url_list(URI + path, params)

def astro():
    path =  '/webhook/xz?'
    # print '-'*100
    # print '十二星座URL:\n'
    for x in astroTuple:
        a = {}
        a['astro'] = x
        a['date'] = today(nodash=True)
        append_to_url_list(URI + path,a)

    print '-'*100

def traffic():
    path =  '/webhook/xx?'
    params = {}
    for city in cityTuple:
        params = {
            'cityName' : city,
            'date' : today(),
        }
        append_to_url_list(URI + path, params)    

def scenic_spots():
    path =  '/webhook/jd?'
    params = {}
    for city in cityTuple:
        params = {
            'spotName' : city,
        }
        append_to_url_list(URI + path, params)



if __name__ == '__main__':
    # 需要在浏览器里打开URL 才能看到渲染效果

    # Server = '172.18.10.39:8080' # UAT
    # Server = 'test-uat-crender.hivoice.cn'

    # Online
    # Server = "172.20.71.42:8080"
    # Server = "172.20.61.237:8080"

    URI = "https://%s/unios-usk-crender" % Server

    weather()
    baike()
    astro()
    traffic()
    scenic_spots()

    open_url_list_in_browser()
    